﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace DreamWork.Net
{
    public class RestAPIClient : IRestAPIClient
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly string _token;
        public RestAPIClient(HttpClient client,IHttpContextAccessor httpContextAccessor)
        {
            Client = client;
            _httpContextAccessor = httpContextAccessor;
            var authToken = _httpContextAccessor?.HttpContext.Request.Headers.FirstOrDefault(x=>x.Key=="Authorization").Value;
            if (!string.IsNullOrEmpty(authToken)) 
            {
                _token = authToken;
            }
        }
        public virtual string Token => _token;
        public HttpClient Client { get; }
        public string APIPath { get; set; }

        public IAuthenTicationOptions Options { get; } = new AuthenTicationOptions() { UseAuthentication = false };

    }
}
